library(ggplot2)
library(haven)
## AMCE and ACIE by post-materialism ##
postmat.coefs <- read.csv("amce_by_postmat.csv")
postmat1 <- dplyr::filter(postmat.coefs, model %in% c("Materialist","Mixed values","Post-materialist"))
postmat2 <- dplyr::filter(postmat.coefs, model %in% c("Mixed values - Materialist","Post-materialist - Materialist","Post-materialist - Mixed values"))
postmat1$model <- factor(postmat1$model, levels = c("Materialist","Mixed values","Post-materialist"))
postmat2$model <- factor(postmat2$model, levels = c("Mixed values - Materialist","Post-materialist - Materialist","Post-materialist - Mixed values"))
ggplot(postmat1, aes(x = estimate, y = level, xmin=low, xmax=high)) +
  geom_point(aes(x = estimate, 
                 y = level), position=position_dodge(width=0.6), size=2) + 
  geom_linerange(aes(x = estimate, 
                     xmin = low,
                     xmax = high),
                 lwd = 0.8, position=position_dodge(width=0.6)) +
  geom_vline(xintercept = 0) +
  scale_y_discrete(limits=c('Letter of no objection granted','(Baseline = Letter of no objection refused)','Police response:','500,000','100,000','(Baseline = 10,000)','Expected turnout:','Associated Press and Reuters broadcast','(Baseline = No international media present)','Media attention:',
                            'Oppose Great Firewall','Oppose Mandatory Putonghua','Oppose Goods and Services Tax','(Baseline = Improve healthcare services)','Theme:')) +
  facet_wrap(~model, nrow = 1) +
  labs(y=NULL, x="Change in Pr(Participate in protest)") +
  theme(text = element_text(size=15), panel.background = element_blank(), axis.line = element_line(colour = "black")) 
ggsave("Figure5a.png", width = 10, height = 6, units = "in", dpi = 350)

ggplot(postmat2, aes(x = estimate, y = level, xmin=low, xmax=high)) +
  geom_point(aes(x = estimate, 
                 y = level), position=position_dodge(width=0.6), size=1.8) + 
  geom_linerange(aes(x = estimate, 
                     xmin = low,
                     xmax = high),
                 lwd = 0.6, position=position_dodge(width=0.6)) +
  geom_vline(xintercept = 0) +
  scale_y_discrete(limits=c('Letter of no objection granted','(Baseline = Letter of no objection refused)','Police response:','500,000','100,000','(Baseline = 10,000)','Expected turnout:','Associated Press and Reuters broadcast','(Baseline = No international media present)','Media attention:',
                            'Oppose Great Firewall','Oppose Mandatory Putonghua','Oppose Goods and Services Tax','(Baseline = Improve healthcare services)','Theme:')) +
  facet_wrap(~model, nrow = 1) +
  labs(y=NULL, x="Difference in changes") +
  theme(text = element_text(size=14), panel.background = element_blank(), axis.line = element_line(colour = "black")) 
ggsave("Figure5b.png", width = 10, height = 6, units = "in", dpi = 350)

## AMCE and ACIE by confidence in personal freedom ##
conf.coefs <- read.csv("amce_by_confidence.csv")
conf.coefs$model <- factor(conf.coefs$model, levels = c("Low confidence","High confidence","Comparison"))
ggplot(conf.coefs, aes(x = estimate, y = level, xmin=low, xmax=high)) +
  geom_point(aes(x = estimate, 
                 y = level), position=position_dodge(width=0.6), size=1.8) + 
  geom_linerange(aes(x = estimate, 
                     xmin = low,
                     xmax = high),
                 lwd = 0.6, position=position_dodge(width=0.6)) +
  geom_vline(xintercept = 0) +
  scale_y_discrete(limits=c('Letter of no objection granted','(Baseline = Letter of no objection refused)','Police response:','500,000','100,000','(Baseline = 10,000)','Expected turnout:','Associated Press and Reuters broadcast','(Baseline = No international media present)','Media attention:',
                            'Oppose Great Firewall','Oppose Mandatory Putonghua','Oppose Goods and Services Tax','(Baseline = Improve healthcare services)','Theme:')) +
  facet_wrap(~model) +
  labs(y=NULL, x="Change in Pr(Participate in protest)     Change in Pr(Participate in protest)                 Difference in changes") +
  theme(text = element_text(size=12), panel.background = element_blank(), axis.line = element_line(colour = "black")) 
ggsave("Figure6a.png", width = 12, height = 5, units = "in", dpi = 350)
 
## AMCE and ACIE by dissatisfaction with personal financial situation ##
econ.coefs <- read.csv("amce_by_econdissat.csv")
econ.coefs$model <- factor(econ.coefs$model, levels = c("Low dissatisfaction","High dissatisfaction","Comparison"))
ggplot(econ.coefs, aes(x = estimate, y = level, xmin=low, xmax=high)) +
  geom_point(aes(x = estimate, 
                 y = level), position=position_dodge(width=0.6), size=1.8) + 
  geom_linerange(aes(x = estimate, 
                     xmin = low,
                     xmax = high),
                 lwd = 0.6, position=position_dodge(width=0.6)) +
  geom_vline(xintercept = 0) +
  scale_y_discrete(limits=c('Letter of no objection granted','(Baseline = Letter of no objection refused)','Police response:','500,000','100,000','(Baseline = 10,000)','Expected turnout:','Associated Press and Reuters broadcast','(Baseline = No international media present)','Media attention:',
                            'Oppose Great Firewall','Oppose Mandatory Putonghua','Oppose Goods and Services Tax','(Baseline = Improve healthcare services)','Theme:')) +
  facet_wrap(~model) +
  labs(y=NULL, x="Change in Pr(Participate in protest)             Change in Pr(Participate in protest)              Difference in changes") +
  theme(text = element_text(size=12), panel.background = element_blank(), axis.line = element_line(colour = "black")) 
ggsave("Figure7a.png", width = 12, height = 5, units = "in", dpi = 350)
